import { createRouter, createWebHistory } from 'vue-router';
import type { App } from 'vue';
import { createRouterGuard } from './guard';
import routes from './helper.ts';

export const router = createRouter({
	history: createWebHistory(import.meta.env.BASE_URL),
	// 控制滚动行为
	scrollBehavior: () => ({ left: 0, top: 0 }),
	routes,
});

/**
 * 创建路由守卫
 */
createRouterGuard(router);

/**
 * 配置路由器
 * @param app
 */
export function setupRouter(app: App) {
	app.use(router);
}
